// pages/sendMessage/sendMessage.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        position: "医生",
        docName: "",
        message: "",
        docList:[],
        show: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.request({
            url: 'https://118.31.170.229:5001/api/CjwAdmin/GetAdminListByPosition?position='+this.data.position,
            method: 'post',
            success: (res) => {
                // console.log(111)
                // console.log(res)
                let newList = []
                res.data.forEach(i => {
                    newList.push(i.adminName)
                }) 
                this.setData({
                    docList: newList
                })
                console.log(this.data.docList)
            }
          })
    },

    onChange() {
        
    },

    sendMessage() {
        let userInfo = wx.getStorageSync('userInfo')
        let params = {
            docName: this.data.docName,
            openId: userInfo.openId,
            wxName: userInfo.Name,
            appContent: this.data.message
        }
        console.log(params)
        wx.request({
            url: 'https://118.31.170.229:5001/api/CjwChatList/UserSendMessage',
            method: 'post',
            data: params,
            success: (res) => {
                console.log(111)
                console.log(res)
                wx.navigateBack({
                    delta: 1,
                  })
                wx.showToast({
                    title: '成功',
                    icon: 'success',
                    duration: 2000
                  })
                
            }
          })
    },

    docChange(event) {
        console.log(event.detail.value)
        this.setData({
            docName:event.detail.value
        })
    },
    onCancel() {
        this.setData({
            show: false,
            docName: ""
        })
    },
    onConfirm() {
        this.setData({
            show: false,
        })
    },

    select() {
        this.setData({
            show: true
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})